Method and system for providing a hardware sort in a graphics system

ABSTRACT

A system and method for providing a sort in a computer system is disclosed. The sort is based on a plurality of values of a key. Each of the plurality of items has an associated value of the plurality of values. The method and system include providing a new item of the plurality of items to a plurality of sort cells. The new item includes a new value of the plurality of values. The plurality of sort cells is for sorting the plurality of items. Each sort cell is for sorting a corresponding item of the plurality of items. The corresponding item has a corresponding value of the plurality of values. The method and system further include comparing the new value to the corresponding value for each of the plurality of sort cells to determine whether to retain the corresponding item. Each of the plurality of sort cells retains the corresponding item if the corresponding item is to be retained. For each of the plurality of sort cells, the method and system determine whether to accept the new item or an item corresponding to the previous sort cell if the corresponding item is not to be retained. If the corresponding item is not to be retained, the method and system allow a sort cell to accept the new item or the item corresponding to the previous sort cell.

CROSS-REFERENCE TO RELATED APPLICATIONS

[0001] The present application is related to co-pending U.S. patentapplication Ser. No. 08/624,261 entitled “Method and Apparatus forIdentifying and Eliminating three-dimensional Objects VisuallyObstructed from a Planar Surface” filed on Mar. 29, 1996. The presentapplication is also related to U.S. patent application Ser. No.08/624,260 entitled “Graphics Processors, System and Method forGenerating Screen Pixels in Raster Order Utilizing a SingleInterpolator” filed on Mar. 29, 1996.

FIELD OF THE INVENTION

[0002] The present invention relates to computer systems, and moreparticularly to a method and system for providing a hardware sort whichis simple to design, simple to use, fast, and applicable to computergraphics system.

BACKGROUND OF THE INVENTION

[0003] Many computer systems must sort items based on the value of a keyin order to achieve certain functions. Such computer systemsconventionally employ a software sort. For example, computer graphicssystems may utilize a software sort in order to render an image. Incurrent computer graphics systems, images of three-dimensional objectscan be depicted on a two dimensional display. In order to give theillusion of depth, computer graphics systems use each objects “z value,”the distance of each object to the viewing plane. In particular, theobjects are ordered based on each object's z value. Thus, the key forsuch a sort is the z value. Once the objects are sorted according totheir z values, the computer graphics system can correctly blend thecolors of translucent objects and opaque objects that can be seenthrough the translucent objects to achieve the proper color to bedisplayed for each pixel.

[0004] In a conventional computer graphics system, the software sortoccurs when a display list is generated through an application. Thedisplay list orders three-dimensional objects based on a key, typicallythe z value. The display list typically orders translucent object fromback to front. Thus, the display list sorts translucent objects.Although they may appear on the display list, opaque objects aretypically sorted using a conventional Z buffer.

[0005] Placing the objects in the order prescribed by the display listallows the computer system to properly depict the images of thethree-dimensional objects on the display. Hardware in the computergraphics system utilizes the display list, a frame buffer, and a zbuffer to render the three-dimensional objects in the order dictated bythe display list. The frame buffer and z buffer describe a portion of athree-dimensional object that is to be rendered. The frame bufferincludes data such as color and alpha values for the portion of theobject, while the z buffer includes corresponding the z values. Theconventional computer graphics system provides the objects described inthe frame and z buffers to the display screen in the order prescribed bythe display list. Consequently, solid objects are rendered first, thentranslucent objects are rendered from back to front. Thus, the displaylist generated by software is used to render the three-dimensionalobjects.

[0006] Although conventional computer graphics systems are capable ofdepicting three-dimensional objects, the software sort required toprovide the display list can be relatively slow. If the software sort isoptimized, the sort time can be reduced to a limited extent. However,development time for the software sort is significantly increased.Moreover, changes to the display list and the software sort creating thedisplay list may be difficult to implement. Finally, since the hardwarerequires a display list in order to properly render the objects, thecomputer system is limited to using those applications which provide asorted display list. Without the display list and the attendant softwaresort, the computer system may not be able to properly depictthree-dimensional objects.

[0007] Accordingly, what is needed is a system and method for sortingitems which does not require a sort performed by software. It would alsobe beneficial if the system and method could be implemented in acomputer graphics system for providing a two dimensional image ofthree-dimensional objects. The present invention addresses such a need.

SUMMARY OF THE INVENTION

[0008] The present invention provides a method and system for providinga sort in a computer system. The sort is based on a plurality of valuesof a key. Each of the plurality of items has an associated value of theplurality of values. The method and system comprise providing a new itemof the plurality of items to a plurality of sort cells. The new itemincludes a new value of the plurality of values. The plurality of sortcells is for sorting the plurality of items. Each sort cell is forsorting a corresponding item of the plurality of items. Thecorresponding item has a corresponding value of the plurality of values.The method and system further comprise comparing the new value to thecorresponding value for each of the plurality of sort cells todetermined whether to retain the corresponding item. Each of theplurality of sort cells retains the corresponding item if thecorresponding item is to be retained. For each of the plurality of sortcells, the method and system determine whether to accept the new item oran item corresponding to the previous sort cell if the correspondingitem is not to be retained. If the corresponding item is not to beretained, the method and system allow a sort cell to accept the new itemor the item corresponding to the previous sort cell.

[0009] According to the system and method disclosed herein, the presentinvention provides a hardware sort which is simple to implement andmodify, fast, and applicable to computer graphics systems.

BRIEF DESCRIPTION OF THE DRAWINGS

[0010]FIG. 1 is a block diagram of a conventional system for depictingthree-dimensional objects on a two dimensional display.

[0011]FIG. 2 is a block diagram depicting a computer graphics systemutilizing the system and method in accordance with the presentinvention.

[0012]FIG. 3 is a block diagram of one embodiment of a system inaccordance with the present invention.

[0013]FIG. 4 is a flow chart of a method for providing a sort inaccordance with the present invention.

[0014]FIG. 5 is a block diagram depicting one embodiment of a sort cellin accordance with the present invention.

[0015]FIG. 6 is a detailed flow chart of a method for providing a sortin accordance with the present invention.

[0016]FIG. 7 is a block diagram of a preferred embodiment of a system inaccordance with the present invention.

[0017]FIG. 8 is a block diagram depicting a preferred embodiment of asort cell in accordance with the present invention.

DETAILED DESCRIPTION OF THE INVENTION

[0018] The present invention relates to an improvement in computersystems which sort items based on a key. The following description ispresented to enable one of ordinary skill in the art to make and use theinvention and is provided in the context of a patent application and itsrequirements. Various modifications to the preferred embodiment will bereadily apparent to those skilled in the art and the generic principlesherein may be applied to other embodiments. Thus, the present inventionis not intended to be limited to the embodiment shown but is to beaccorded the widest scope consistent with the principles and featuresdescribed herein.

[0019] Many conventional systems achieve a particular desired result bysorting items based on the value of a key associated with the items. Forexample, computer graphics systems which depict images ofthree-dimensional objects on a two dimensional display use a softwaresort to create the illusion of depth. The key that is used for thissoftware sort is typically an object's “z value”, or distance from theviewing plane at a particular pixel.

[0020]FIG. 1 depicts a block diagram of a conventional system 10 forproviding a two dimensional display of three-dimensional objects.Typically, the three-dimensional objects are broken into polygons, suchas triangles, for display. Consequently, rendering a three dimensionalobject will be discussed in the context of rendering polygons. Asoftware application 12 is used to display the polygons. The application12 calls drivers 14 which create a display list.

[0021] The display list contains the x, y, and z coordinates, alpha orblending value, color, and other information for each polygon. Thedisplay list also lists the information relating to each polygon in theorder in which the polygons will be rendered to the display 22. Thedisplay list typically places polygons which are part of opaque or solidobjects first on the display list. These opaque objects are typicallysorted by a z-buffer 17, described below. The polygons for translucentobjects are generally next on the display list. The translucent polygonsare ordered from back to front, or highest to lowest z value, on thedisplay list. The ordering of the polygons allows the computer system toproperly depict the images of the three-dimensional objects on thedisplay. The drivers 14 sort the translucent polygons based on the zvalue of each polygon in order to create the display list. Note that ingeneral, a polygon may contain a range of z values. Consequently, thesort provided by the display list may actually be more complex to takeinto account the range of z values. Thus, in the conventional computergraphics system 10, the translucent polygons are sorted by software todetermine the order in which the objects will be rendered to thedisplay.

[0022] Once the polygons are properly ordered in the display list, ahardware renderer 16 can begin the process of rendering the polygons tothe display 22. The display list is provided to the hardware renderer16, which prepares data relating to the polygons for display. Thehardware renderer 16 creates a z buffer 17 and a frame buffer 18 tostore data relating to each of the polygons. The z buffer 17 includesthe z values for each pixel in the polygon. The frame buffer 18 includesthe colors for each pixel in the polygon.

[0023] For each polygon on the display list, data from the z buffer 17and frame buffer 18 are then provided to the display controller 20. Thedisplay controller 20 then outputs the data on the display 22. Thus,each polygon is rendered in the order dictated by the display list.Because the polygons are rendered in the order prescribed by the displaylist, the conventional system 10 can correctly blend the colors oftranslucent objects and opaque objects that can be seen through thetranslucent objects to achieve the proper color for each pixel to bedisplayed.

[0024] Although the conventional system 10 shown in FIG. 1 is capable ofdisplaying three-dimensional objects on a two dimensional display, thosewith ordinary skill in the art will realize that the software sortrequired to provide the display list has several disadvantages. Thesoftware sort can be relatively slow if not optimized. If the softwaresort is optimized, the time required to perform the software sort can bereduced to a certain extent. However, development time for the softwaresort is significantly increased. Moreover, changes to the display listand the software sort creating the display list may be difficult or timeconsuming to implement. Finally, the fact that the hardware renderer 16requires the data to be provided in the order of the display list limitsthe computer system 10 to using applications 12 which provide thetranslucent polygons sorted on the display list and, therefore, performa software sort. Without having the translucent polygons properly sortedin the display list, the computer system 10 may not be able to properlydepict three-dimensional objects.

[0025] The present invention provides a method and system for providinga sort in a computer system. The sort is based on a plurality of valuesof a key. Each of the plurality of items has an associated value of theplurality of values. The method and system comprise providing a new itemof the plurality of items to a plurality of sort cells. The new itemincludes a new value of the plurality of values. The plurality of sortcells is for sorting the plurality of items. Each sort cell is forsorting a corresponding item of the plurality of items. Thecorresponding item has a corresponding value of the plurality of values.The method and system further comprise comparing the new value to thecorresponding value for each of the plurality of sort cells to determinewhether to retain the corresponding item. Each of the plurality of sortcells retains the corresponding item if the corresponding item is to beretained. For each of the plurality of sort cells, the method and systemdetermine whether to accept the new item or an item corresponding to theprevious sort cell if the corresponding item is not to be retained. Ifthe corresponding item is not to be retained, the method and systemallow a sort cell to accept the new item or the item corresponding tothe previous sort cell.

[0026] The present invention will be described in terms of a computergraphics system which sorts fragments using a specified number of sortcells. However, one of ordinary skill in the art will readily recognizethat this method and system will operate effectively for other computersystems which sorts other items and for another number of sort cells.

[0027] To more particularly illustrate the method and system inaccordance with the present invention, refer now to FIG. 2 depicting acomputer graphics system 50 in which the present invention could beimplemented. The computer system 50 is described more completely inco-pending U.S. patent application Ser. No. 08/624,261 entitled “Methodand Apparatus for Identifying and Eliminating Three-Dimensional ObjectsVisually Obstructed from a Planar Surface”. The computer graphics system50 includes a central processing unit (CPU) 52, a display 54, a userinterface 56 such as a keyboard or mouse or other communicating device,a memory 55, and an image generating unit 60 coupled with a bus 58.Note, however, that nothing prevents the method and system from beingimplemented in a different computer system having other components.

[0028] The image generating unit includes an interface 61 connected tothe bus 58. The interface 61 transmits data to a data processing unit62. A processor block 65 is coupled with the data processing unit 62.The processor block 65 identifies data describing polygons(“intersecting polygons”) which intersect a z axis extending from aselected pixel in an x-y plane corresponding to a screen of the display54. In a preferred embodiment, the processor block 65 includes aprocessor for each polygon that may intersect the z axis extending fromthe selected pixel. The data associated with an intersecting polygon istermed a fragment. Thus, data relating to each selected pixel includesfragments for each of the intersecting polygons.

[0029] A quick z unit 66 receives the fragments from each intersectingpolygon associated with the selected pixel and removes fragments forcertain polygons which are obstructed without determining the precise zvalue of the polygon. The quick z 66 is described more completely inco-pending U.S. patent application Ser. No. 08/624,261 entitled “Methodand Apparatus for Identifying and Eliminating Three-Dimensional ObjectsVisually Obstructed from a Planar Surface”. The interpolator 68 receivesthe fragments for the polygons intersecting the particular pixel andinterpolates the data, including interpolating texture, color, and alphavalues for the fragment. The interpolator 68 provides the fragments foreach of the intersecting polygons to a hardware sorter 100 constructedin accordance with the present invention. The hardware sorter 100 sortsthe fragments for the intersecting polygons based on the value of a keyassociated with the fragment. In a preferred embodiment, the key is thez value for the fragment at the selected pixel.

[0030] To more particularly illustrate the hardware sorter 100 inaccordance with the present invention, refer now to FIG. 3 depicting oneembodiment of the hardware sorter 100. Note that although the hardwaresorter 100 is described in conjunction with the computer graphics system50, nothing prevents the use of the hardware sorter 100 in anothercomputer system. Thus, the hardware sorter 100 will be described assorting based on a particular key (the z value) associated with aparticular item (the fragment for an intersecting polygon for a selectedpixel). However, nothing prevents the hardware sorter 100 from sortingbased on another key or accepting other types of data. Thus, thehardware sorter 100 is applicable to other systems requiring a sort,such as a router in a network.

[0031] The hardware sorter 100 includes a plurality of sort cells 110.Note that although only four sort cells 110 are depicted, nothingprevents the hardware sorter 100 from having another number of sortcells 110. In a preferred embodiment, the number of sort cells 110 is atleast equal to the number of items to be sorted. Thus, in a preferredembodiment, the number of sort cells 110 is the same as the number ofprocessors in the processor block 65. Also in a preferred embodiment,the number of sort cells is sixteen. However, nothing prevents the useof another number of sort cells 110. Similarly, nothing prevents thenumber of sort cells 110 from being different from the number ofprocessors in the processor block 65.

[0032] Alternate embodiments of the present invention can also be usedwhere overflow may occur. Overflow occurs where there are more items tosort than there are sort cells. The alternate embodiments used foroverflow cases may depend on the application for which the hardwaresorter 100 is used. For example, where the embodiment is used in acomputer graphics system subject to overflow, fragments which aredetermined to be “solid” may be passed through the hardware sorter 100.In such a case, the hardware sorter 100 will only sort non-solidfragments. The solid fragments may be sorted in a different portion ofthe image generating unit 60. Note that in such an embodiment,“non-solid” may apply to partial fragments such as those generated byanti-aliasing. Moreover, whether a fragment is solid or non-solid neednot be based solely on a fragment's alpha value.

[0033] The hardware sorter 100 further includes a new input line 102 forproviding a new fragment in parallel to each of the sort cells 110 vianew input 120. Each sort cell 110 also includes an output 130. Theoutput 130 of a sort cell 130 is coupled to an input of a next sort cell110. The output 130 of the last sort cell 110 is not coupled to anothersort cell 110. Instead, the output 130 of the last sort cell 110provides the output of the hardware sorter 100. Although not depicted inFIG. 3, in an alternate embodiment, each sort cell could have anothernumber of new input lines 102, another number of outputs 130, and/oranother number of inputs. In such a system each sort cell 110 could sortanother number of fragments.

[0034] Refer now to FIG. 4 depicting a method 150 in accordance with thepresent invention which uses the hardware sorter 100. Each sort cell 110may have a fragment which corresponds to it (“corresponding fragment”).Each corresponding fragment includes a corresponding z value, which isused to sort the fragment, and corresponding data, such as color andalpha values for the corresponding fragment. A new fragment, includingthe new z value, is broadcast to each of the plurality of sort cells110, via step 152. Note that in a preferred embodiment, if the newfragment is the first fragment for a pixel, the first fragment is alsoplaced in the first sort cell 110. Where the new fragment is a firstfragment for a pixel when the hardware sorter 100 is empty, the firstfragment is placed in the first sort cell 110. Preferably, this isaccomplished by indicating that data in other sort cells 110 is invalid.However, nothing prevents the present invention from using anothermethod for placing the first fragment in the first sort cell 110 whenthe hardware sorter 100 is empty.

[0035] Steps 154 through 164 are performed for each sort cell 110 in thehardware sorter 100 that takes part in the sort. The new z value for thenew fragment is compared to the corresponding z value via step 154.Based on this comparison, each sort cell 110 retains the correspondingfragment, accepts the new fragment, or accepts the fragmentcorresponding to a previous sort cell 110. Thus, it is determinedwhether the sort cell 110 will retain the corresponding fragment,including the corresponding z value, via step 156. If the correspondingfragment is to be retained, then the sort cell 110 keeps thecorresponding fragment via step 158. If the corresponding fragment isnot to be retained, then in step 160 it is determined whether the sortcell 110 is to take the fragment corresponding to a previous sort cell110. If the sort cell 110 is to accept this fragment, the sort cell 110takes the fragment corresponding to the previous cell and passes itscorresponding fragment to be accepted by the next sort cell 110 via step162. If the fragment is not to be taken by the sort cell 110, the sortcell 110 takes the new fragment and passes its corresponding fragment tobe accepted by the next cell in step 164. As a result, the new fragmentis inserted into the hardware sorter 100 in the appropriate sort cell110. This process continues to sort all of the fragments provided to thehardware sorter.

[0036] Refer now to FIG. 5 depicting one embodiment of a sort cell 110in accordance with the present invention. The sort cell 110 is coupledto a new input 120. The new input 120 includes a new data input 122, anew key input 124, and a new identification input 126. The sort cell 110includes an input 140 and an output 130. The input 140 includes acontrol signal input 141, a previous key input 142, and a previous datainput 143. The output 130 includes a control signal output 132, a keyoutput 134, and a data output 136. The sort cell 110 also includes an ORgate 113 which combines the control signal input with a control signalprovided by the controller 115 to be output on the control signal output132. In a preferred embodiment, the control signal output 132 is coupledto the control signal input 141 of a next sort cell. The key output 134is coupled to the key input 142 of the next sort cell. Also in apreferred embodiment, the data output 136 is coupled to the data input143 of the next sort cell. Consequently, to pass a correspondingfragment to the next sort cell 110, the corresponding key and data areprovided over the key output 134 and the data output 136.

[0037] The sort cell 110 further includes a comparator 114 and acontroller 115 coupled with the comparator 114. In addition, the sortcell 110 contains a key selector 116, a key storage 117, a data selector118 and a data storage 119. The corresponding key is stored in the keystorage 117. The corresponding data for the corresponding fragment isstored in the data storage 119. Note that although the sort cell 110 isdepicted as having key storage 117 and data storage 119 internal to thesort cell 110, nothing prevents the method and system from storing thekey and/or the data in a location remote from the sort cell 110, such asin a random access memory. The key selector 116 and data selector 118are controlled by a controller 115. The controller 115 can also providea “take data” signal which is ORed with a previous cell's “take data”signal by the OR gate 113. This combination signal is provided to thecontrol signal output 132. Thus, when either a previous sort cell 110 orthe current sort cell 110 provides a “take data” signal, the currentsort cell 110 also asserts a “take data” signal over the control signaloutput 132. When a “take data” signal is asserted over control signaloutput 132, the next sort cell 110 will accept the correspondingfragment previously stored in the sort cell 110.

[0038] In one embodiment, the key selector 116 and data selector 118 aremultiplexers. The key selector 116 selects between the new key, a keycorresponding to a previous cell input through previous key input 142,and a new key input from new key input 122. Similarly, the data selectorselects between the new data provided by the new data input 124, datacorresponding to a previous sort cell 110 that is provided throughprevious data input 143, and the corresponding data.

[0039] In a preferred embodiment, fragments for pixels in a scan lineare provided one after another to the hardware sorter 100. As a result,the hardware sorter 100 should be capable of sorting the fragments forone pixel without affecting the order of the fragments for anotherpixel. This capability can be provided using the controller 115 and apixel identification. Consequently, in a preferred embodiment, eachfragment for a pixel includes a pixel identification. The newidentification is provided to the sort cell 110 through the newidentification input 126.

[0040] In a preferred embodiment, the pixel identification is providedby a counter, not shown. Also in a preferred embodiment, each fragmenthas a fragment type associated with it. Preferably, there are fourfragment types, N, L, E and EOL. An N fragment is simply an nth fragmentin the pixel. This could be any fragment for the pixel except for thelast fragment. An L fragment is a last fragment for a particular pixel.An E (empty) fragment indicates that there are no intersecting polygonsfor the pixel. An EOL fragment indicates that the hardware sorter 100should be flushed, for example due to an end of line or end of frame.

[0041] In the preferred embodiment the fragment types are transformed toan identification by the counter, not shown. The counter provides aunique number for a set of fragments corresponding to a particularpixel. The counter does so by incrementing after every L or E fragment.Consequently, all fragments for the first pixel have an identificationof one. All fragments for the second pixel have an identification oftwo. The identification for each pixel may be incremented until an EOLfragment which flushes the hardware sorter 100 is reached. Thisidentification is provided to each of the sort cells 110 along with thefragment. Consequently, in a preferred embodiment, a correspondingfragment for a particular sort cell 110 includes a correspondingidentification in addition to the corresponding z value and thecorresponding data.

[0042] Note, however, the identification merely allows the hardwaresorter 100 to distinguish between different pixels having fragments inthe hardware sorter 100 at the same time. Because there are N sort cells110 in the hardware sorter 100, there can be at most fragments for Ndifferent pixels in the hardware sorter 100. Consequently, theidentification may represent up to only N different values to ensurethat each fragment in the hardware sorter 100 can be associated with aunique pixel. For example, for a hardware sorter 100 having four sortcells 110, an identification having only two bits (four differentvalues) can be used. The counter can run, reusing values for pixelswhich cannot both have fragments in the hardware sorter 100 at the sametime.

[0043] To more particularly describe the operation of the hardwaresorter 100, refer to FIGS. 3, 5, and 6. FIG. 6 depicts a method 200 forproviding a hardware sort using the identification in accordance withthe present invention. In step 202, a new fragment is provided to all ofthe sort cells 110 through the new input line 102 and new input 120. Thenew fragment includes the new z value, new data and new identification.In a preferred embodiment, the new z value for the fragment is providedto each sort cell 110 via the new key input 124. Similarly, the new datais provided via the new data input 122. The new identification isprovided through new identification input 126. If the new fragment isthe first fragment for a pixel, then the new fragment is automaticallyinput to the first sort cell 110.

[0044] The steps 204 through 224 for the method 200 are performed byeach sort cells 110 that is taking part in the sort. In step 204, it isdetermined if the new identification is the same as the correspondingidentification. In a preferred embodiment, step 204 is performed by thecontroller 115. Depending on whether the new identification is the sameas the corresponding identification, the sort cell 110 behavesdifferently.

[0045] If the identifications match, the comparator 114 is used tocompare the new z value to the corresponding z value, via step 214. Inone embodiment, this comparison determines whether the corresponding zvalue is greater than the new z value. In the embodiment depicted inFIG. 4, the results of the comparison are provided to the controller115. However, nothing prevents the resultant of the comparator 114 frombeing used directly to control the key selector 116, the data selector118, or generate a signal over control signal output 132.

[0046] If the corresponding z value is not greater than the new z value,the then the new fragment will not displace the corresponding fragmentor the fragment corresponding to any sort cell 110 located prior to thesort cell 110. Thus, if the corresponding z is not greater than the newz, the sort cell 110 retains the corresponding fragment via step 216. Ina preferred embodiment, the corresponding z value and data are retainedin step 216 because the controller 115 signals the selectors 116 and 118to choose the input from the key storage 117 and data storage 119,respectively.

[0047] When the resultant of the comparator 114 indicates that thecorresponding z value is greater than the new z value, the sort cell 110will not retain its state. Consequently, the “take data” signal isasserted via step 218. In a preferred embodiment, the “take data” signalis simply the resultant of the comparator 114 indicating that thecorresponding z value is greater than the new z value. To determine whatthe sort cell 110 will do, the controller determines whether the “takedata” signal from a previous sort cell has been asserted via step 220.

[0048] When the corresponding fragment (z value and data) is not to beretained, the sort cell 110 must determine whether to accept the new keyand data provided over lines 124 and 122, respectively, or to accept thez value and data from a previous cell provided via previous key input142 and previous data input 143. Consequently, the controller 115determines whether the “take data” signal from a previous cell has beenasserted over the control signal input 141 via step 220. If the “takedata” signal is not asserted, then the sort cell 110 accepts the newfragment via step 222. Consequently, when the resultant of thecomparator 114 indicates that the corresponding z value is greater thanthe new z value and the take data signal from the previous sort cell isnot provided via control signal input 141, the controller 115 allows thesort cell 110 to accept the new data. To do so, the controller providesthe selectors 116 and 118 with a signal indicating that the values fromthe new key input 124 and the new data input 122 are to chosen. The newz value and new data are then stored in the key storage 117 and datastorage 118, respectively.

[0049] If the “take data” signal is asserted over the control signalinput 141, then via step 224 the sort cell 110 accepts the fragmentcorresponding to the previous cell. Consequently, when the resultant ofthe comparator 114 indicates that the corresponding z value is greaterthan the new z value and the “take data” signal from the previous sortcell 110 is provided via control signal input 141, the controller 115allows the sort cell 110 to accept the z value and data corresponding toa previous cell. To do so, the controller provides the selectors 116 and118 with a signal indicating that the values from the previous key input142 and the previous data input 143 to the selectors 116 and 118 are tobe selected. Thus, the z value and data corresponding to the previouscell are stored in the key storage 117 and data storage 118,respectively.

[0050] If the identifications do not match, then via step 206, it isensured that the new fragment is not sorted by the sort cell 110. In apreferred embodiment, step 206 is performed by turning off thecomparator 114 for the sort cell 110. Turning the comparator off assuresthat the sort cell 110 will not accept the new data, thereby preventingthe new fragment from being sorted with fragments for another pixel. Thecontroller 115 then determines if the “take data” signal from theprevious cell has been provided to the sort cell 110 via step 208. Ifthe “take data” signal has not been asserted, then the sort cell 110retains the corresponding fragment via step 210. In a preferredembodiment, the controller accomplishes this by controlling theselectors 116 and 118 to choose the input from the key storage 117 anddata storage 119, respectively. If the “take data” signal has beenasserted, then via step 212, the sort cell 110 accepts the fragment fromthe previous sort cell 110 and, due to the OR gate 113, asserts the“take data” signal over the control signal output 132.

[0051] Note that for the first sort cell 110 in the hardware sorter 100,a take data signal is never asserted over the control signal input 141.As a result, the first sort cell 110 will only transfer itscorresponding fragment to the second sort cell when its corresponding zvalue is less than the new z value, a fragment for a new pixel arrives,or the hardware sorter 100 is flushed. Thus, the z value for thefragment stored in the first sort cell 110 is the smallest for aparticular pixel.

[0052] In a preferred embodiment, the pixels input to the hardwaresorter 100 will be output in order. The OR gate 113 in each sort cell110 allows the hardware sorter 100 to accomplish this. A first fragmentfor a current pixel is input to the first sort cell 110. As subsequentfragments for the current pixel are sorted by the hardware sorter 100,the “take data” signal may be asserted by a sort cell 110 near the topof the hardware sorter 100. Because of the OR gate 113, each subsequentsort cell 110 will assert the “take data” signal over the control signaloutput 132. As a result, fragments for prior pixels and fragments forthe current sort cell which have a higher z value are passed down thehardware sorter 100 in order. Eventually, the fragments for these pixelsare output by the last sort cell 110 in the hardware sorter. As aresult, the pixels pass through the hardware sorter 100 in order and thefragments for each pixel are properly sorted. In a preferred embodiment,at the end of a line, an EOL fragment causes the “take data” signal tobe asserted by all of the sort cells 110. As a result, the hardwaresorter 100 is flushed. Consequently, the system 50 is synchronized,ensuring that pixels are written at a particular time.

[0053] In a preferred embodiment, the new fragment is broadcast inparallel to the sort cells 110 in a first clock cycle. In the same clockcycle, the sort cells perform a comparison, insert the new fragment inthe appropriate place, and, if necessary, move fragments which aredisplaced by the new fragment farther down the hardware sorter 100.Consequently, each new fragment is sorted in a single cycle in apreferred embodiment. The number of sort cells is based on the order ofthe number of fragments to be sorted. As a result, the number of cyclesbetween providing a pixel to the first cell of the hardware sorter 100and providing the sorted pixel to the output of the last sort cell 110is substantially the same as the number of sort cells 110. In general,this time is at least as good as the time achieved by an optimizedsoftware sort. Although there may be a delay between the first pixelbeing input to the hardware sorter 100 and the first pixel being outputby the hardware sorter 100 (“latency”), the sort for each pixel isperformed in a single clock cycle. Therefore, a sort performed inaccordance with the present invention is typically faster than anoptimized software sort.

[0054] Although FIG. 5 depicts each sort cell 110 as having an internalcontroller 115, in a preferred embodiment, the controller 115 for eachsort cell is combined to a single controller outside of the sort cells.FIG. 7 depicts a preferred embodiment of a hardware sorter 300 inaccordance with the present invention. Note that although the hardwaresorter 300 will be described in conjunction with the computer graphicssystem 50, nothing prevents the use of the hardware sorter 300 inanother computer system. Thus, the hardware sorter 300 will be describedas sorting based on a particular key (the z value) associated withparticular data (the fragments for a pixel including color and alphavalues) nothing prevents the hardware sorter 300 from sorting based onanother key or accepting other types of data. Thus, the hardware sorter300 is applicable to other systems requiring a sort, such as a router ina network.

[0055] The hardware sorter 300 includes a plurality of sort cells 310.Note that although only four sort cells 310 are depicted, nothingprevents the hardware sorter 300 from having another number of sortcells 310. In a preferred embodiment, the number of sort cells 310 is atleast equal to the number of items to be sorted. Thus, in a preferredembodiment, the number of sort cells 310 is the same as the number ofprocessors in the processor block 65. Also in a preferred embodiment,the number of sort cells 310 is sixteen.

[0056] The hardware sorter 300 further includes a new input line 320 forproviding a new fragment in parallel to each of the sort cells 310 vianew input 320. Each sort cell 310 also includes an output 330. Theoutput 330 of a sort cell 130 is coupled to an input of a next sort cell310. The output 330 of the last sort cell 310 is not coupled to anothersort cell 310. Instead, the output 330 of the last sort cell 310provides the output of the hardware sorter 300. The hardware sorter 300also includes a controller 350 which controls the sort cells 310 throughcontrol lines 360.

[0057] To more particularly describe the hardware sorter 300 refer toFIG. 8, depicting a sort cell 310 in accordance with the presentinvention. The sort cell 310 is coupled to a new input 320. The sortcell 310 includes a control line 360, an output 330, and an input 340.The new input 320 includes new data input 322 and new key input 324. Theinput 340 includes previous key input 312 and previous data input 313.The output 330 includes corresponding key output 334 and correspondingdata output 336. The control line 360 includes control signal output 362and control signal input 364. The sort cell 310 also includes a keyselector 316, key storage 317, data selector 318, and data storage 319.In one embodiment, the key storage 317 and data storage 319 existoutside of the sort cell 310.

[0058] The sort cell 310 and hardware sorter 300 function similarly tothe sort cell 110 and hardware sorter 100, respectively. The primarydifference is that the hardware sorter 300 includes a single controller350 separate from the sort cells 300. In the hardware sorter 300, thecontroller 350 takes on the functions of the controllers 115 for all ofthe sort cells 110 in the hardware sorter 100. In addition, each sortcell 310 includes an input 364 for the signals used to control the keyselector 116 and the data selector 118. The sort cell 310 also includesan output 362 to provide the resultant from the comparator 314 to thecontroller 350. Because the controller 350 controls all of the sortcells 310, in a preferred embodiment no control signal is passed betweenthe sort cells 310. However, the controller 350 controls the sort cells310 to provide the same functions as provided by the hardware sorter100.

[0059] As discussed above, in a preferred embodiment, the hardwaresorter 100 and the hardware sorter 300 include a number of sort cells onwhich is at least the same as the number of items to be sorted. However,nothing prevents fewer sort cells from being used. This is particularlytrue if an appropriate sort cell 110 or 310 were provided with aheuristic in order to choose which item to discard in the event that thenumber of items to be sorted is greater than the number of sort cells110 or 310.

[0060] For example, in the computer graphics system 50, thecorresponding fragment for the last sort cell 110 or 310 is the fragmentfarthest from the viewer. Suppose that the new fragment has a z valuenear that of the fragment corresponding to the last sort cell 110 or310. A heuristic included in the last sort cell 110 or 310 could takethe z value and other information into account to determine how torespond to the new fragment, for example by discarding one of thefragments. Consequently, although a preferred embodiment includes atleast as many sort cells as items expected to be sorted, nothingprevents the use of fewer sort cells.

[0061] A method and system has been disclosed for providing a hardwaresort. Because the new item (fragment) to be sorted can be broadcast toall sort cells in parallel and because each sort cell can simultaneouslyperform functions, the system and method provide an efficient sort. Inaddition, each sort cell can be the same as other sort cells. When thenumber of items sorted or size of the hardware sorter are desired to bechanged, sort cells be easily added or subtracted from the hardwaresorter. Consequently, the time required to develop the method and systemis reduced. In addition, because each sort cell can be made the same,the hardware sorter is a regular array. Consequently, the hardwaresorter is relatively simple to lay out once the layout of a single cellis determined.

[0062] Although the present invention has been described in accordancewith the embodiments shown, one of ordinary skill in the art willreadily recognize that there could be variations to the embodiments andthose variations would be within the spirit and scope of the presentinvention. Accordingly, many modifications may be made by one ofordinary skill in the art without departing from the spirit and scope ofthe appended claims.

What is claimed is:
 1. A system for sorting items in a computer system,the sort being based on a plurality of values of a key, each item havinga value of the plurality of values, the system comprising: A pluralityof sort cells for sorting at least a portion of the plurality of items,each sort cell for sorting a corresponding item, the corresponding itemhaving a corresponding value, each sort cell further having anassociated key storage for storing the corresponding value, a comparatorfor comparing the corresponding value to a new value associated with anew item, a first input, and an output, the first input of the each ofthe plurality of sort cells except a first sort cell being coupled withthe output of a previous sort cell; and a second input coupled with eachof the plurality of sort cells, the second input for providing the newitem to the plurality of sort cells; such that each of the plurality ofsort cells compares the new value to the corresponding value todetermine whether to retain the corresponding item and retains thecorresponding item if it is determined that the corresponding item is tobe retained; and such that each of the plurality of sort cells acceptseither the new item or an item corresponding to the previous sort cellif the corresponding item is not to be retained and provides thecorresponding item over the output if the corresponding item is notretained.
 2. The system of claim 1 wherein the comparator furtherprovides a resultant, and wherein each of the plurality of sort cellsfurther includes a controller coupled with the comparator and thestorage, the controller for determining whether the corresponding itemis to be retained based on the resultant and for allowing each sort cellfurther accept the new item or the item corresponding to the previoussort cell if the corresponding item is not to be retained.
 3. The systemof claim 2 wherein the output of each of the plurality of sort cellsprovides a signal to the next cell indicating that the correspondingitem is to be accepted by the next cell if the corresponding item is notto be retained.
 4. The system of claim 3 wherein the controller furtherdetermines that the corresponding item is to be retained when thecomparator indicates the corresponding value is not greater than the newvalue.
 5. The system of claim 4 wherein the controller determines thatthe new item is to be accepted when the corresponding value is greaterthan the new value and the previous cell has not provided a signalindicating that the item corresponding to the previous cell is to beaccepted by the sort cell.
 6. The system of claim 5 wherein thecontroller determines that the item corresponding to the previous cellis to be accepted when the corresponding value is greater than the newvalue and the previous cell has provided a signal indicating that theitem corresponding to the previous cell is to be accepted by the sortcell.
 7. The system of claim 6 wherein each of the plurality of itemsfurther has an identification associated with it and wherein thecontroller further allows the plurality of sort cells to sort theportion of the plurality of items having the same identification.
 8. Thesystem of claim 7 wherein each of the plurality of items has dataassociated with it and wherein each of the plurality of sort cellsfurther has an associated data storage for storing the data associatedwith the corresponding item, the sort cell providing the data associatedwith the corresponding item over the output if the corresponding item isnot to be retained, and the sort cell storing data associated with thenew item or data associated with the item corresponding to the previouscell in the data storage if the corresponding item is not to beretained.
 9. The system of claim 8 wherein the computer system is acomputer graphics system including a display, wherein each of theplurality of items is a fragment, the key is a z value, and the dataassociated with the corresponding item includes color and blending data.10. The system of claim 7 wherein each of the plurality of items hasdata associated with it, and wherein the system further comprises: datastorage for storing the data associated with the corresponding item foreach of the plurality of sort cells.
 11. The system of claim 10 whereinthe computer system is a computer graphics system including a display,wherein each of the plurality of items is a fragment, the key is a zvalue, and the data associated with the corresponding item includescolor and blending data.
 12. The system of claim 7 wherein the keystorage is located remote from each sort cell.
 13. The system of claim 1wherein the comparator further provides a resultant, and wherein thesystem further includes: a controller coupled with the plurality of sortcells, the controller for determining whether the corresponding item foreach of the plurality of sort cells is to be retained based on theresultant of each of the plurality of sort cells, the controller furtherinstructing each sort cell to accept the new item or the itemcorresponding to the previous sort cell if the corresponding item is notretained.
 14. The system of claim 13 wherein the controller furtherprovides a signal to each of the plurality of sort cells indicating thatthe item corresponding to the previous sort cell is to be accepted ifthe corresponding item is not to be retained.
 15. The system of claim 14wherein the controller determines whether the corresponding item is tobe retained when the comparator indicates the corresponding value is notgreater than the new value.
 16. The system of claim 15 wherein thecontroller determines that the new item is to be accepted when thecorresponding value is greater than the new value and the previous cellhas not provided a signal indicating that the item corresponding to theprevious cell is to be accepted by the sort cell.
 17. The system ofclaim 16 wherein the controller determines that the item correspondingto the previous cell is to be accepted when the corresponding value isgreater than the new value and the previous cell has provided a signalindicating that the item corresponding to the previous cell is to beaccepted by the sort cell.
 18. The system of claim 17 wherein each ofthe plurality of items further has an identification associated with itand wherein the controller further allows the plurality of sort cells tosort the portion of the plurality of items having the sameidentification.
 19. The system of claim 18 wherein each of the pluralityof items further has an identification associated with it; and whereinthe controller further allows the plurality of sort cells to sort theportion of the plurality of items having the same identification. 20.The system of claim 19 wherein each of the plurality of items has dataassociated with it and wherein each of the plurality of sort cellsfurther includes: data storage for storing the data associated with thecorresponding item, the sort cell providing the data associated with thecorresponding item over the output if the corresponding item is not tobe retained, and the sort cell storing data associated with the new itemor data associated with the item corresponding to the previous cell inthe data storage if the corresponding item is not to be retained. 21.The system of claim 20 wherein the computer system is a computergraphics system including a display, wherein each of the plurality ofitems is a fragment, the key is a z value, and the data associated withthe corresponding item includes color and blending data.
 22. The systemof claim 19 wherein each of the plurality of items has data associatedwith it and wherein the system further comprises: data storage forstoring the data associated with the corresponding item for each of theplurality of sort cells.
 23. The system of claim 22 wherein the computersystem is a computer graphics system including a display, wherein eachof the plurality of items is a fragment, the key is a z value, and thedata associated with the corresponding item includes color and blendingdata.
 24. The system of claim 23 wherein the data storage is locatedremote from each sort cell.
 25. A method sorting a plurality of items ina computer system, the sort being based on a plurality of values of akey, each of the plurality of items having an associated value of theplurality of values, the method comprising the steps of: (a) providingat least one new item of the plurality of items to a plurality of sortcells, the at least one new item including at least one new value of theplurality of values, the plurality of sort cells for sorting theplurality of items, each sort cell for sorting at least onecorresponding item of the plurality of items, the at least onecorresponding item having at least one corresponding value of theplurality of values; (b) for each of the plurality of sort cells,comparing the at least one new value to the at least one correspondingvalue to determine whether to retain the at least one correspondingitem; (c) for each of the plurality of sort cells, retaining the atleast one corresponding item if the at least one corresponding item isto be retained; (d) for each of the plurality of sort cells, determiningwhether to accept the at least one new item or at least one itemcorresponding to the previous sort cell if the at least onecorresponding item is not retained; (e) if the at least onecorresponding item is not to be retained, accepting the at least one newitem or the item corresponding to the previous sort cell.
 26. The methodof claim 25 wherein the steps (a) through (e) are performed in one clockcycle.
 27. The method of claim 26 wherein the at least one correspondingitem further includes data associated with it, and wherein the methodfurther comprises the step of: (f) storing the data associated with theat least one corresponding item in a data storage, the data beingretained if the at least one corresponding item is to be retained andbeing provided over the output if the at least one corresponding item isnot to be retained.
 28. The method of claim 27 wherein the computersystem is a computer graphics system and the data associated with the atleast one corresponding item further includes color and blending datafor a particular fragment for a particular pixel on the display.
 29. Themethod of claim 28 further comprising the steps of: (g) providing anidentification for each of the plurality of items; and (h) sorting theportion of the plurality of items having the same identification.